package com.tiger.novelbld;

import com.tiger.novelbld.base.BaseActivity;
import com.tiger.novelbld.base.CommonUtil;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

public class ReadActivity extends BaseActivity {
	
	private int txtnum=0;
	private ImageView prePerson,nextPerson;
	private TextView title,content;
	private ScrollView contentScroll;
	private String str="title<TITLE>content";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.read);
        
        initView();
        CommonUtil.initAdView(this);
    }
    
    public void initView(){
    	prePerson=(ImageView)this.findViewById(R.id.prePerson);
    	nextPerson=(ImageView)this.findViewById(R.id.nextPerson);
    	content=(TextView)this.findViewById(R.id.book_content);
    	
    	title=(TextView)this.findViewById(R.id.title);
    	
    	prePerson.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(txtnum==0){
					Toast.makeText(ReadActivity.this, "已是第一节", Toast.LENGTH_LONG).show();
					return;
				}
				txtnum--;
				readTxtByNum();
			}
    	});
    	nextPerson.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(txtnum==16){
					Toast.makeText(ReadActivity.this, "已是最后一节", Toast.LENGTH_LONG).show();
					return;
				}
				txtnum++;
				readTxtByNum();
			}
    	});
    	
    	readTxtByNum();
    }
    private void readTxtByNum(){
    	str=CommonUtil.getTextByTxt(this, txtnum+".xml");
    	String[] titleStr=str.split("<TITLE>");
    	if(titleStr!=null&&titleStr.length==2){
    		title.setText(titleStr[0]);
        	content.setText(Html.fromHtml(titleStr[1]));
    	}
    }
   
}